#include "widget.h"
#include "ui_widget.h"
#include"QPushButton"
#include"QGridLayout"
#include"QSpacerItem"
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    QPushButton* btn1=new QPushButton("按钮1");
     QPushButton* btn2=new QPushButton("按钮2");
      QPushButton* btn3=new QPushButton("按钮3");
      QPushButton* btn4=new QPushButton("按钮4");
    btn1->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);//垂直默认不拉伸，需要手动设置
    btn2->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    btn3->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    btn4->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
     QGridLayout* layout=new QGridLayout();
     QSpacerItem* spacer=new QSpacerItem(20,20);
     layout->addWidget(btn1,600,500);
     layout->addWidget(btn2,600,600);//行列的数字只决定在布局中的顺序
     layout->addWidget(btn3,700,500);
     layout->addWidget(btn4,700,600);
     layout->setRowStretch(600,1);//第一行垂直拉伸比例为1
     layout->setRowStretch(700,2);//第二行拉伸比例为2
     this->setLayout(layout);

}

Widget::~Widget()
{
    delete ui;
}

